_realname=yosys
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.r10474.b0d4c6395
pkgrel=1
pkgdesc="A framework for RTL synthesis tools (mingw-w64)"
arch=('any')
license=("ISC")
url="http://www.clifford.at/yosys/"
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-ghdl"
  "${MINGW_PACKAGE_PREFIX}-python"
)
checkdepends=("${MINGW_PACKAGE_PREFIX}-iverilog")
makedepends=(
  'flex'
  'git'
  "${MINGW_PACKAGE_PREFIX}-ghdl"
  "${MINGW_PACKAGE_PREFIX}-python"
)

_commit='b0d4c63'
source=(
  "${_realname}::git://github.com/YosysHQ/${_realname}.git#commit=${_commit}"
  "ghdl-yosys-plugin::git://github.com/ghdl/ghdl-yosys-plugin.git#commit=6671d04"
)
sha256sums=(
  'SKIP'
  'SKIP'
)

pkgver() {
  cd "${_realname}"
  printf "0.9.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

build() {
  cd "${srcdir}/${_realname}"

  if [ "$CARCH" = "i686" ]; then
    make config-msys2-32
  fi

  if [ "$CARCH" = "x86_64" ]; then
    make config-msys2-64
  fi

  mv "${srcdir}/ghdl-yosys-plugin"/src frontends/ghdl
  echo "ENABLE_GHDL=1" >> Makefile.conf
  echo "GHDL_PREFIX=${MINGW_PREFIX}" >> Makefile.conf

  make \
    GIT_REV="${_commit}" \
    PRETTY=0
}

check() {
  cd "${srcdir}/${_realname}"
  make test
}

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install
}
